<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="admin/common/common_css :: commonHeader('编辑系统权限')">
</head>
<body>
<article class="page-container">
    <form class="form form-horizontal" id="form-authority-edit">
        <input type="hidden" id="authorityId" name="authorityId" th:value="${editAuthority.authorityId }" />
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>权限名称：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" placeholder="权限名称（必填）" th:value="${editAuthority.authorityName }" id="authorityName" name="authorityName" maxlength="50" />
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>权限标识：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" placeholder="权限标识（必填，anon：匿名，authc：需要登录，other：其他自定义）" th:value="${editAuthority.authorityKey }" id="authorityKey" name="authorityKey" maxlength="50" />
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>权限地址：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" placeholder="权限地址（必填，需要权限验证的URL地址，如果有多个地址请使用英文状态下逗号分隔）" th:value="${editAuthority.authorityUrl }" id="authorityUrl" name="authorityUrl" maxlength="500" />
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">权限说明：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <textarea name="authorityDesc" maxlength="200" class="textarea"  placeholder="权限说明...200个字符以内" onKeyUp="javascript:textareaLength(this);"><th:block th:text="${editAuthority.authorityDesc }"></th:block></textarea>
                <p class="textarea-numberbar"><em class="textarea-length"><span id="textareaLengthSpan">0</span></em>/200</p>
            </div>
        </div>
        <div class="row cl">
            <div style="text-align: center;">
                <button class="btn btn-primary radius" type="submit">
                    <i class="Hui-iconfont">&#xe632;</i> 保存
                </button>
                &nbsp;&nbsp;
                <button onClick="layer_close();" class="btn btn-default radius" type="button">
                    &nbsp;&nbsp;取消&nbsp;&nbsp;
                </button>
            </div>
        </div>
    </form>
</article>
<div th:include="admin/common/common_js :: onLoadJS"></div>
<script type="text/javascript" th:src="@{/js/admin.ui/lib/jquery.validation/1.14.0/jquery.validate.js}"></script>
<script type="text/javascript" th:src="@{/js/admin.ui/lib/jquery.validation/1.14.0/validate-methods.js}"></script>
<script type="text/javascript" th:src="@{/js/admin.ui/lib/jquery.validation/1.14.0/messages_zh.js}"></script>
<script type="text/javascript">
    $(function(){
        $("#form-authority-edit").validate({
            rules:{
                authorityName:{required:true, minlength:2, maxlength: 50,remote: {
                    url: '/pestdiagnosis/sys/authority/validateIsAuthorityExist',
                    type: 'post',
                    dataType: 'json',
                    data: {validateType:'authorityName',authorityId:function () {return $.trim($("#authorityId").val());},authorityName: function () {return $.trim($("#authorityName").val());}},
                    dataFilter: function (data) {
                        if(data != null && data != '') {
                            if (eval('(' + data + ')').data == '0') {
                                return true;
                            } else {
                                return false;
                            }
                        } else {
                            return false;
                        }
                    }
                }},
                authorityKey:{required:true, minlength:2, maxlength: 50},
                authorityUrl:{required:true, minlength:2, maxlength: 500,remote: {
                    url: '/pestdiagnosis/sys/authority/validateIsAuthorityExist',
                    type: 'post',
                    dataType: 'json',
                    data: {validateType:'authorityUrl',authorityId:function () {return $.trim($("#authorityId").val());},authorityUrl: function () {return $.trim($("#authorityUrl").val());}},
                    dataFilter: function (data) {
                        if(data != null && data != '') {
                            if (eval('(' + data + ')').data == '0') {
                                return true;
                            } else {
                                return false;
                            }
                        } else {
                            return false;
                        }
                    }
                }}
            },
            messages:{
                authorityName:{remote:'权限名称已经存在'},
                authorityUrl:{remote:'权限地址已经存在'}
            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                send(
                    '/pestdiagnosis/sys/authority/edit',
                    $('#form-authority-edit').serialize(),
                    function (data) {
                        if(data.result == 0) {
                            layer.msg(data.message, {icon: 1,time: 1500}, function() {
                                window.parent.location.href = "/pestdiagnosis/sys/authority/list";
                            });
                        } else {
                            layer.msg(data.message, {icon: 5,time: 1500});
                            $('#authorityName').focus();
                        }
                    },
                    function (res) {

                    }
                );
            }
        });
    });
    // 计算文本域字符长度
    function textareaLength(obj) {
        $('#textareaLengthSpan').text($(obj).val().length);
    }
</script>
</body>
</html>